/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

typedef struct {
    uint8_t lastVal:1;
    uint8_t count:5;        //  滤波次数
    uint8_t result:1;
    uint8_t click:1;
}KEY_DEBOUNCE_t;

typedef union
{
    uint8_t all;
    struct
    {
        uint8_t key0         : 1;
        uint8_t key1         : 1;
        uint8_t key2         : 1;
        uint8_t key3         : 1;
    }bit;
} IoIn_t;
/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
extern uint8_t  p1ms_req;                                            //  1ms flag

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
#define sleep(ms) {                                         \
    static uint32_t lastTime;                                 \
    static bool   isInit;                                   \
    if (!isInit) { lastTime = timer_1ms; isInit = true; }   \
    if ((uint32_t)(timer_1ms - lastTime) < (ms)) return;      \
    else lastTime = timer_1ms;                              \
} ;

#define isRise(result, now, last)                           \
{                                                           \
    if ((now != last) & now)                                \
        { result = true; }                                  \
    else                                                    \
        { result = false; }                                 \
    (last) = (now);                                         \
}
/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define WKUP_Pin GPIO_PIN_0
#define WKUP_GPIO_Port GPIOA
#define KEY0_Pin GPIO_PIN_1
#define KEY0_GPIO_Port GPIOA

/* USER CODE BEGIN Private defines */
#define MAX_KEY_NUM        2                               // IO输入口的数量

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
